/*
 * @Author: your name
 * @Date: 2024-05-22 22:15:48
 * @LastEditTime: 2024-05-23 11:13:40
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \.leetcode\53.最大子数组和.cpp
 */
/*
 * @lc app=leetcode.cn id=53 lang=cpp
 *
 * [53] 最大子数组和
 */

// @lc code=start
class Solution {
public:
    int result = INT_MIN;
    int count = 0;
    int maxSubArray(vector<int>& nums) {
        for(int i = 0; i < nums.size(); i++){
            count += nums[i];
            if(count > result){
                result = count;// 更新最大值
            }
            if(count < 0){
                count = 0;
            }
        }
        return result;
    }
    
};
// @lc code=end

